<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/> 

<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta name="decorator" content="default" />
</head>
<body>
<script>
var datatable;
var prjName;
// 删除数据后重新加载数据
function queryMaster() {
	var oSettings = datatable.fnSettings();
	oSettings._iDisplayStart = 0;
	datatable.fnClearTable(0); //清空数据
	/* if($('#prjName').val() !=''&& $('#prjName') != null){
		prjName = $('#prjName');
		query(prjName);
	}else{ */
		datatable.fnDraw(); //重新加载数据 
	//}
}

//模糊查询数据
function queryMasterKbName(){
	alert($("#kbName").val());
	/* var oSettings = datatable.fnSettings();
	oSettings._iDisplayStart = 0;
	datatable.fnClearTable(0); //清空数据 */
	baseQuery($("#kbName").val());
}

//删除方法 
function del(id,kbName){
	Otod.Msg.confirm('确定删除此知识库【'+kbName+'】?',"确认删除", function(){
       
        	delOk(id);
        
    });
}

//删除方法 
function delOk(id){
	Otod.ajax({
	    url: "${ctx}/kb/main/delMaster.do?uuid=" + id,
	    type: "GET",
	    successFn: function(data) {
	    	queryMaster();
	    }
	});
}


//保存成功，修改按钮状态
function saveSuc(){
		
}

//修改 
function editMaster(id){
	window.location.href="masterEdit.jsp?id="+id
}



$(document).ready(function() {
	//$('#masterSaveForm').bootstrapValidator();
	//$('#roleSaveForm').data('bootstrapValidator').validate();
	baseQuery("");
});

function baseQuery(kbName){
	
	var masterTableColums = [
	            	         //定义列 删除
	                        {
	            				"mData":"uuid",
	            				"sClass": "center",
	            				"bSortable": false,
	            				"mRender" : function(data, type, row) {
	            					return '<a class="red" href="javascript:del(\''+data+'\',\''+row.kbName+'\')"><i class="icon-trash bigger-130"></i></a>';
	            				}
	                        },
	                        { //修改
	            				"mData":"uuid",
	            				"sClass": "center",
	            				"bSortable": false,
	            				"mRender" : function(data, type, row) {
	            					return '<a  href="javascript:editMaster(\''+data+'\')"><i class="icon-pencil bigger-130"></i></a>';
	            				}
	                        },
	                        {"mData":"kbName"},
	                        {"mData":"kbType"},
	                        {"mData":"kbSrc"},
	                        {"mData":"authorDate"},
	                        {"mData":"status"},
	                        {"mData":"depict"}
	                       
	                ];
	            	
	                //初始化dataTable
	            	datatable = $('#masterTable').dataTable( {
	            		
	                	'sAjaxSource': '${ctx}/kb/main/queryMaster.do?kbName='+kbName,	//请求数据源 
	            		'bServerSide':true,							//是否启动服务器端数据导入
	            		"bLengthChange" : false,
	            		"bInfo" : true,
	            		"bPaginate" : true,
	                    'bFilter': false,                       	//是否使用内置的过滤功能。
	                    'aoColumns': masterTableColums,
	                     "sDom": '<"toolbar">frtip', 
	                     "oLanguage": oLanguage
	            	});
	                
	
}
</script>
<div class="row">
	<div class="col-sm-12">
		<div class="row">
			<h3 class="header smaller lighter blue">
				<small>知识库列表</small>
			</h3>	
			<form class="form-horizontal" role="form" name="masterQuery" id="masterQueryForm" action="" method="get">
				<div class="col-sm-4" >
					<label for="q_prjName" class="col-sm-5 control-label">知识库名称</label>
					<div class="col-sm-7">
						<input type="text" class="form-control input-sm" id="kbName" name="kbName" placeholder="项目名称">
					</div>
				</div>
				<div class="col-sm-4">
				    <button type="button" class="btn btn-xs btn-info" onclick="queryMasterKbName();"><i class="icon-search"></i>查询</button>
					<button class="btn btn-xs btn-default" type="reset"><i class="icon-undo"></i>重置</button>
				</div>
				<div class="col-sm-4"></div>
			</form>
		</div>
			
		<div class="row">
			<div class="col-xs-12">
				<a href = "${ctx}/jsp/kb/main/masterEdit.jsp" ><button id="addBtn" class="btn btn-xs btn-success" type="button"  onclick="addPrj(this);"><i class="icon-plus-sign"></i>新增知识库</button></a>
			</div>
		</div>
		<div class="row">
			<h3 class="header smaller lighter blue">
			</h3>
			<div class="col-xs-12">
				<div class="table-responsive">
					<table id="masterTable" class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th width="5%">删除</th>
								<th width="5%">修改</th>
								<th width="10%">知识库名称</th>
								<th width="10%">知识库类型</th>
								<th width="10%">知识库来源</th>
								<th width="10%">知识库日期</th>
								<th width="10%">知识库状态</th>
								<th width="10%">知识库描述</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
				</div>
			</div>
		</div>
							
	</div>
</div>
</body>
